package ${controllerPath};

import ${servicePath}.I${EntityName}Service;
import ${dtoPath}.*;
import ${voPath}.${EntityName}Vo;
import ${entityPath}.${EntityName};
import com.lenovo.cnbu.common.core.web.controller.BaseController;
import com.lenovo.cnbu.common.log.annotation.Log;
import com.lenovo.cnbu.common.core.web.page.TableDataInfo;
import com.lenovo.cnbu.common.security.annotation.RequiresPermissions;
import com.lenovo.cnbu.common.log.enums.BusinessType;
import com.lenovo.cnbu.common.core.domain.R;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.lenovo.cnbu.common.core.annotation.RepeatSubmit;

/**
* ${table_annotation}
* @Description:${table_annotation}控制层
* @author ${author}
* @date ${date}
*/
@RestController
@RequestMapping("/${lowName}")
@RequiredArgsConstructor(onConstructor = @_(@Autowired))
@Api(tags ="99: ${table_annotation}")
@ApiSupport(author = "${author}")
public class ${EntityName}Controller  extends  BaseController{

    /**
    *  国际化配置说明参考
    *  ${lowName} = ${table_annotation}
    *  ${lowName} = ${lowName}
    */

    /**
    * ${table_annotation}Service
    */
    private final  I${EntityName}Service ${lowName}Service;

<#if add>
    /**
    * 新增${table_annotation}
    * @param dto
    * @return
    */
    @RequiresPermissions("${lowName}:insert")
    @PostMapping
    @Log(title = "${lowName}", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增${table_annotation}", notes="新增${table_annotation}。前端按钮权限标识符设置：${lowName}:insert")
    @RepeatSubmit
    public R<Long> insert(@RequestBody @Valid ${EntityName}AddDto dto) {
        return R.ok(${lowName}Service.insert(dto));
    }
</#if>
<#if update>
    /**
    * 修改${table_annotation}
    * @param dto
    * @return
    */
    @RequiresPermissions("${lowName}:edit")
    @PutMapping
    @Log(title = "${lowName}", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改${table_annotation}", notes="修改${table_annotation}。前端按钮权限标识符设置：${lowName}:edit")
    public R update(@RequestBody @Valid ${EntityName}UpdateDto dto) {
        ${lowName}Service.update(dto);
        return R.ok();
    }
</#if>
<#if delete>
    /**
    * 批量删除${table_annotation}
    * @param ids
    * @return
    */
    @RequiresPermissions("${lowName}:remove")
    @DeleteMapping
    @Log(title = "${lowName}", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除${table_annotation}", notes="删除${table_annotation}。前端按钮权限标识符设置：${lowName}:remove")
    public R deleteBatch(@ApiParam(value = "主键id", required = true) @RequestParam(value = "ids")  List<Long> ids) {
        ${lowName}Service.deleteBatch(ids);
        return R.ok();
    }
</#if>
<#if page>
    /**
    *
    * 分页查询${table_annotation}
    * @param dto
    * @return
    */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询${table_annotation}", notes="分页查询${table_annotation}")
    public  TableDataInfo<List<${EntityName}Vo>> page(@RequestBody @Valid ${EntityName}PageDto dto){
        //注意：分页只针对startPage后第一条sql生效,如果list之前需要查询,请在startPage前执行
        startPage();
        List<${EntityName}> list = ${lowName}Service.list(dto);
        TableDataInfo tableInfo = getDataTable(list);
        tableInfo.setRows(${lowName}Service.convertToVo(list));
        return tableInfo;
    }
</#if>
<#if getVoById>
    /**
    *
    * 根据id查询${table_annotation}
    * @param id
    * @return
    */
    @GetMapping("/getById")
    @ApiOperation(value = "根据id查询${table_annotation}", notes="根据id查询${table_annotation}")
    public  R<${EntityName}Vo> getById(@ApiParam(value = "主键id", required = true) @RequestParam(value = "id")  Long id){
        ${EntityName}Vo vo = ${lowName}Service.getVoById(id);
        return R.ok(vo);
    }
</#if>
<#if getAll>
    /**
    *
    * 查询所有${table_annotation}
    * @return R<List<${EntityName}Vo>>
    */
    @GetMapping("/getAll")
    @ApiOperation(value = "查询所有${table_annotation}", notes="查询所有${table_annotation}")
    public  R<List<${EntityName}Vo>> getAll(){
        return R.ok(${lowName}Service.getAll());
    }
</#if>
}
